/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package domain.controllers;

import domain.Entity.EntityGestor;
import domain.Entity.EntityTarea;
import domain.Entity.EntityTrabajador;
import domain.Entity.EntityUsuario;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import managers.TareaManager;
import managers.UsuarioManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.view.RedirectView;

/**
 *
 * @author jorge
 */
public class obtenerUsuarioController implements Controller{
   
    UsuarioManager um = UsuarioManager.getInstance();

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        ModelAndView mav = new ModelAndView();
       HttpSession session = request.getSession();
        EntityUsuario eu = (EntityUsuario) session.getAttribute("usuario");
        if(eu == null){
            mav.setView(new RedirectView("login.htm"));
            return mav;
        }else{
        TareaManager tm = TareaManager.getInstance();
        
        if(eu.getTipo().equals("gestor")){
            List tareasGestor = new ArrayList();
            List l = tm.obtenerEtiquetas(eu);
            EntityGestor eg = um.obetenerGestor(eu.getDni());
            session.setAttribute("tareasdelInforme", tareasGestor);
            session.setAttribute("gestorUsuario", eg);
            session.setAttribute("etiquetas", l);
       
        }else{
             
             EntityTrabajador etr = um.getTrabajador(eu.getDni());
             tm.TareasyEtiquetasTrabajador(etr,session);
             
                session.setAttribute("trabajadorUsuario", etr);
             }
        
        mav.setView(new RedirectView("crearInforme.htm"));
        return mav;
        }
    }
}
